package com.qiwenshare.file.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qiwenshare.common.anno.MyLog;
import com.qiwenshare.common.result.RestResult;
import com.qiwenshare.common.util.security.SessionUtil;
import com.qiwenshare.file.api.ArchiveApproveService;
import com.qiwenshare.file.component.InitData;
import com.qiwenshare.file.domain.ArchiveApprove;
import com.qiwenshare.file.dto.archive.ApproveDTO;
import com.qiwenshare.file.vo.ArchiveApproveVo;
import com.qiwenshare.file.vo.archive.ArchiveVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 用户档案审批表(ArchiveApprove)表控制层
 *
 * @author MJ
 * @since 2023-10-12 16:51:47
 */
@RestController
@RequestMapping("archiveApprove")
public class ArchiveApproveController{
    /**
     * 服务对象
     */
    @Resource
    private ArchiveApproveService archiveApproveService;


    public static final String CURRENT_MODULE = "档案审批管理";

    @Operation(summary = "分页查询档案审批", description = "分页查询档案审批", tags = {CURRENT_MODULE})
    @GetMapping(value = "/page")
    @MyLog(operation = "分页查询档案审批", module = CURRENT_MODULE)
    @ResponseBody
    public RestResult<ArchiveApproveVo> queryPage(
            @Parameter(description = "档案名称", required = false) String archiveName,
            @Parameter(description = "申请人", required = false) String userName,
            @Parameter(description = "审批状态", required = false) Integer approveStatus,
            @Parameter(description = "当前页", required = true) long currentPage,
            @Parameter(description = "页面数量", required = true) long pageCount) {
        //approveStatus : 1 待审批 2已审批
        IPage<ArchiveApproveVo> page = archiveApproveService.getVoList(archiveName, userName, approveStatus, currentPage, pageCount);
        return RestResult.success().dataList(page.getRecords(), page.getTotal());
    }


    @Operation(summary = "查询档案审批", description = "查询档案审批", tags = {CURRENT_MODULE})
    @GetMapping(value = "/getApproveOne")
    @MyLog(operation = "查询档案审批", module = CURRENT_MODULE)
    @ResponseBody
    public RestResult<ArchiveApproveVo> getApproveOne(
            @Parameter(description = "档案名称", required = true) String archiveId) {
        return RestResult.success().data(archiveApproveService.getApproveOne(archiveId, SessionUtil.getUserId()));
    }


    @Operation(summary = "档案审批", description = "档案审批", tags = {CURRENT_MODULE})
    @PostMapping(value = "/approve")
    @MyLog(operation = "档案审批", module = CURRENT_MODULE)
    @ResponseBody
    public RestResult<Boolean> approve(@RequestBody ApproveDTO approveDTO) {
        return RestResult.success().data(archiveApproveService.approve(approveDTO));
    }
}

